<?php
/**
 * Created by PhpStorm.
 * User: lx
 * Date: 2020/1/13
 * Time: 10:46
 */
namespace app\mtadminapi\controller;

use app\mtadminapi\model\MtUserLivePeople;
use app\util\ReturnCode;
use rusty\generator\util\DB;

/**
 * 用户评价管理
 * Class AdminSysAssessManage
 * @package app\mtadminapi\controller
 */
class AdminSysAssessManage extends Base
{
    /**
     * 商户评论列表
     * @return array
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function assessList(){
        $shopID = intval($this->request->get("shopID"));
        if(!$shopID){
            return $this->bindError(ReturnCode::EMPTY_PARAMS,"需要shopID");
        }
        $assessList = (new MtUserLivePeople())->where("shopID",$shopID)->select();
        if(!$assessList){
            return $this->bindError(ReturnCode::DB_READ_ERROR,"商户评论查询失败");
        }
        return $this->bindSuccess("查询成功",$assessList);
    }

    /**
     * 商家回复评论
     * @return array
     */
    public function replyAssess(){
        $replyData= $this->request->post();
        if(!$replyData['assessID'] || !intval($replyData['assessID'])){
            return $this->bindError(ReturnCode::EMPTY_PARAMS,"需要评论ID");
        }
        if(!$replyData['reply']){
            return $this->bindError(ReturnCode::EMPTY_PARAMS,"需要回复内容");
        }
        $replyData['adminID'] = session("adminUser.adminID");
        $replyData['cTime'] = time();
        $res = \think\Db::table("mt_user_assess_reply")->inser($replyData,true);
        if(!$res){
            return $this->bindError(ReturnCode::DB_SAVE_ERROR,"添加回复失败",$replyData);
        }
        return $this->bindSuccess("添加成功",$replyData);
    }
}